#this is an example practice file on how to use XML in python


#=======WRITING XML=========
from xml.dom.minidom import Document
import maya.cmds as cmds

doc = Document()   #creates a new xml document

root_node = doc.createElement("scene_information")  #set the root node
doc.appendChild(root_node)  #append that to the doc as a child

selection = cmds.ls(sl=True)

for object in selection:
    print (object)
    object_node = doc.createElement("Ctrl") #create node for the object
    root_node.appendChild(object_node)  #make that a child of the rootNode

    object_translation = cmds.getAttr(object + ".translate")
    object_node.setAttribute(str(object), str(object))  #add a name attr with the object
    object_node.setAttribute("translateX", str(object_translation[0][0])) #add attributes to the xml node for the object
    object_node.setAttribute("translateY", str(object_translation[0][1]))
    object_node.setAttribute("translateZ", str(object_translation[0][2]))

path = '/users/mmurray/Desktop/Projects/Python/XML/xmlFiles/'
xml_file = open(path + 'myFile.xml', 'w')
xml_file.write(doc.toprettyxml())
xml_file.close()

print
print (doc.toprettyxml())



